<?php

	class %%Object%% extends Controller {

		function __construct() {
			parent::Controller();
			$this->load->model('%%object%%s_model', '%%object%%');
		}

		function index() {
			$this->list%%Object%%s();	
		}
		
		function list%%Object%%s() {
			$data['%%object%%s'] = $this->%%object%%->findAll();
			$this->load->view('List%%Object%%s', $data);
		}

		function create($flag=null) {
			if($flag == "new") {
        $this->set('%%object%%/create/new');
      } else {
          $data->action = '%%object%%/create/new';
				  $this->load->view('Create%%Object%%',$data);
      }
		}

		function delete($id) {
			$my%%Object%% = $this->__get%%Object%%($id);
			$this->%%object%%->delete($my%%Object%%);	
			$this->list%%Object%%s();
		}	

		function edit($id) {
      $this->set('%%object%%/edit/'.$id,$id);
		}

		function set($action,$id=null) {
%%formValidation%%
      if ($this->form_validation->run() == FALSE) {
        if($id) { //edit
          if(!validation_errors()) {
            $data = $this->__get%%Object%%($id);
          }
        } else { //create new
          
        }
        $data->action = $action;
  		  $this->load->view('Create%%Object%%',$data);
      } else {
        if($id) { //edit
			  $my%%Object%% = $this->__get%%Object%%($id);
%%formReader%%
				$this->%%object%%->update($my%%Object%%);
        } else { // new
			  $my%%Object%% = new %%Object%%s_model();
%%formReader%%
				$this->%%object%%->create($my%%Object%%);
        }
        redirect('%%object%%');
      }
		}
    	
		function show($id) {
			$my%%Object%% = $this->__get%%Object%%($id);
			$data['%%object%%'] = $my%%Object%%;
			$this->load->view('Show%%Object%%', $data);
		}

		function __get%%Object%%($id) {
			return $this->%%object%%->findByPrimaryKey($id);
		}
}
